package com.example.doer.reading.AppAdapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.ab.image.AbImageLoader;
import com.example.doer.reading.AppDataModel.Theme;
import com.example.doer.reading.R;

import java.util.List;

/**
 * Created by 杨轩昂 on 2017/7/21.
 */



public class categorysAdapter extends BaseAdapter {
    Context context;
    List<Theme> list;

    private LayoutInflater inflater;

    private AbImageLoader abImageLoader;

    public categorysAdapter(Context c, List<Theme> l)
    {
        this.context=c;
        this.list = l;

        this.inflater = LayoutInflater.from(context);
        abImageLoader= AbImageLoader.getInstance(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Theme getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = LayoutInflater.from(context).inflate(R.layout.item_category,null);
        ImageView imageView = (ImageView) view.findViewById(R.id.item_category);
        TextView textView = (TextView) view.findViewById(R.id.tv_category);
        ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
        Theme Theme =  getItem(position);
        textView.setText(Theme.getThemeName());
        abImageLoader.display(imageView,progressBar,"http://192.168.191.1/Reading/ImageDoServlet?Action=download&Category=CategoryImage&ImageName="+Theme.getThemeID(),300,300);
        return view;
    }

}
